/*
 * @Description:
 * @Version:
 * @Autor: tangwc
 * @Date: 2023-05-02 16:08:01
 * @LastEditors: tangwc
 * @LastEditTime: 2023-05-02 22:51:20
 * @FilePath: \stm32_lvgl8.3_demo\User\bsp_driver\Src\tp_i2c.c
 *
 *  Copyright (c) 2023 by tangwc, All Rights Reserved.
 */
#include "i2c.h"
#include "tp_i2c.h"
#include <stdio.h>



uint32_t tp_i2c_read_len(uint8_t reg_addr, uint8_t *data, uint8_t len)
{
    uint32_t ret;
    ret = HAL_I2C_Master_Transmit(&hi2c2, TP_DRIVER_WRITE, &reg_addr, 1, 1000);
    //printf("HAL_I2C_Master_Transmit:%ld\n",ret);
    ret |= HAL_I2C_Master_Receive(&hi2c2, TP_DRIVER_READ, data, len, 1000);
    //printf("HAL_I2C_Master_Receive:%ld\n",ret);
    return ret;
}

uint32_t tp_i2c_write_byte(uint8_t reg_addr, uint8_t data)
{
    uint32_t ret;
    uint8_t write_buf[2] = {reg_addr, data};
    ret = HAL_I2C_Master_Transmit(&hi2c2, TP_DRIVER_WRITE, write_buf, sizeof(write_buf), 1000);
    return ret;
}
